﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtAspNet;

namespace WebUI.Reservation
{
    public partial class Reservation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid();
            }
        }
        protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "Allow")
            {
                int id = int.Parse(Grid1.DataKeys[e.RowIndex][0].ToString());
                Model.OpenReservation m = BLL.OpenReservationMange.SelectByID(id);
                m.confirmed = true;
                if (BLL.OpenReservationMange.Update(m))
                {
                    BindGrid();
                }
                else
                {
                    Alert.ShowInTop("失败！", "错误", MessageBoxIcon.Error);
                }
            }
            if (e.CommandName == "Decline")
            {
                int id = int.Parse(Grid1.DataKeys[e.RowIndex][0].ToString());
                BLL.OpenReservationMange.Delete(id);
                BindGrid();
            }
        }

        private void BindGrid()
        {
            Grid1.DataSource = BLL.OpenReservationMange.GetList(" confirmed = 'false'");
            Grid1.DataBind();
        }
    }
}